<<<<<<< HEAD
import request from '@/utils/request'

/**
 * 获取评价列表
 * @returns {Promise} 包含评价数据的Promise
 */
export function getReviews() {
  return request({
    url: '/api/reviews',
    method: 'get'
  })
=======
import { get, post, put, del } from '@/utils/request'

// 获取评价列表
export function getReviewsList(params = {}) {
  return get('/reviews', params)
}

// 获取评价详情
export function getReviewDetail(reviewId) {
  return get(`/reviews/${reviewId}`)
}

// 获取评价统计
export function getReviewStats(params = {}) {
  return get('/reviews/stats', params)
}

// 回复评价
export function replyReview(reviewId, data) {
  return post(`/reviews/${reviewId}/reply`, data, {
    showLoading: true,
    loadingText: '发送回复中...'
  })
}

// 申诉评价
export function appealReview(reviewId, data) {
  return post(`/reviews/${reviewId}/appeal`, data, {
    showLoading: true,
    loadingText: '提交申诉中...'
  })
}

// 删除回复
export function deleteReply(reviewId) {
  return del(`/reviews/${reviewId}/reply`)
}

// 获取申诉记录
export function getAppealList(params = {}) {
  return get('/reviews/appeals', params)
}

// 获取申诉详情
export function getAppealDetail(appealId) {
  return get(`/reviews/appeals/${appealId}`)
}

// 撤销申诉
export function cancelAppeal(appealId) {
  return post(`/reviews/appeals/${appealId}/cancel`)
}

// 批量回复评价
export function batchReplyReviews(reviewIds, replyContent) {
  return post('/reviews/batch-reply', {
    reviewIds,
    replyContent
  })
}

// 导出评价数据
export function exportReviewsData(params = {}) {
  return get('/reviews/export', params, {
    responseType: 'blob'
  })
}

// 获取评价分析数据
export function getReviewAnalysis(params = {}) {
  return get('/reviews/analysis', params)
}

// 获取评价标签统计
export function getReviewTagStats() {
  return get('/reviews/tag-stats')
}

// 获取客户满意度趋势
export function getSatisfactionTrend(timeRange = '30d') {
  return get('/reviews/satisfaction-trend', { timeRange })
}

// 获取服务质量分析
export function getServiceQualityAnalysis() {
  return get('/reviews/service-quality-analysis')
}

// 获取差评原因分析
export function getBadReviewAnalysis() {
  return get('/reviews/bad-review-analysis')
}

// 获取评价关键词分析
export function getReviewKeywordAnalysis() {
  return get('/reviews/keyword-analysis')
}

// 标记评价为有用
export function markReviewHelpful(reviewId) {
  return post(`/reviews/${reviewId}/helpful`)
}

// 举报恶意评价
export function reportMaliciousReview(reviewId, data) {
  return post(`/reviews/${reviewId}/report`, data)
}

// 获取评价回复模板
export function getReplyTemplates() {
  return get('/reviews/reply-templates')
}

// 创建回复模板
export function createReplyTemplate(data) {
  return post('/reviews/reply-templates', data)
}

// 更新回复模板
export function updateReplyTemplate(templateId, data) {
  return put(`/reviews/reply-templates/${templateId}`, data)
}

// 删除回复模板
export function deleteReplyTemplate(templateId) {
  return del(`/reviews/reply-templates/${templateId}`)
}

// 评价等级常量
export const REVIEW_RATINGS = {
  EXCELLENT: 5,    // 好评
  GOOD: 4,         // 好评
  AVERAGE: 3,      // 中评
  POOR: 2,         // 差评
  TERRIBLE: 1      // 差评
}

export const REVIEW_RATING_TEXT = {
  [REVIEW_RATINGS.EXCELLENT]: '非常满意',
  [REVIEW_RATINGS.GOOD]: '满意',
  [REVIEW_RATINGS.AVERAGE]: '一般',
  [REVIEW_RATINGS.POOR]: '不满意',
  [REVIEW_RATINGS.TERRIBLE]: '非常不满意'
}

export const REVIEW_RATING_COLOR = {
  [REVIEW_RATINGS.EXCELLENT]: 'success',
  [REVIEW_RATINGS.GOOD]: 'success',
  [REVIEW_RATINGS.AVERAGE]: 'warning',
  [REVIEW_RATINGS.POOR]: 'danger',
  [REVIEW_RATINGS.TERRIBLE]: 'danger'
}

// 评价类型常量
export const REVIEW_TYPES = {
  GOOD: 'GOOD',       // 好评 (4-5星)
  MEDIUM: 'MEDIUM',   // 中评 (3星)
  BAD: 'BAD'          // 差评 (1-2星)
}

export const REVIEW_TYPE_TEXT = {
  [REVIEW_TYPES.GOOD]: '好评',
  [REVIEW_TYPES.MEDIUM]: '中评',
  [REVIEW_TYPES.BAD]: '差评'
}

export const REVIEW_TYPE_COLOR = {
  [REVIEW_TYPES.GOOD]: 'success',
  [REVIEW_TYPES.MEDIUM]: 'warning',
  [REVIEW_TYPES.BAD]: 'danger'
}

// 申诉状态常量
export const APPEAL_STATUS = {
  PENDING: 'PENDING',       // 待处理
  REVIEWING: 'REVIEWING',   // 审核中
  APPROVED: 'APPROVED',     // 申诉成功
  REJECTED: 'REJECTED',     // 申诉失败
  CANCELLED: 'CANCELLED'    // 已撤销
}

export const APPEAL_STATUS_TEXT = {
  [APPEAL_STATUS.PENDING]: '待处理',
  [APPEAL_STATUS.REVIEWING]: '审核中',
  [APPEAL_STATUS.APPROVED]: '申诉成功',
  [APPEAL_STATUS.REJECTED]: '申诉失败',
  [APPEAL_STATUS.CANCELLED]: '已撤销'
}

export const APPEAL_STATUS_COLOR = {
  [APPEAL_STATUS.PENDING]: 'warning',
  [APPEAL_STATUS.REVIEWING]: 'primary',
  [APPEAL_STATUS.APPROVED]: 'success',
  [APPEAL_STATUS.REJECTED]: 'danger',
  [APPEAL_STATUS.CANCELLED]: 'info'
}

// 评价标签常量
export const REVIEW_TAGS = {
  POSITIVE: [
    '服务态度好', '清洗干净', '及时送达', '专业技术', '价格合理',
    '包装仔细', '沟通顺畅', '效率高', '质量好', '值得推荐'
  ],
  NEGATIVE: [
    '服务态度差', '清洗不干净', '送达延迟', '技术不专业', '价格偏高',
    '包装粗糙', '沟通困难', '效率低', '质量差', '有异味',
    '衣物损坏', '颜色变化', '缩水', '起球', '褪色'
  ]
}

// 获取评价类型
export function getReviewType(rating) {
  if (rating >= 4) return REVIEW_TYPES.GOOD
  if (rating === 3) return REVIEW_TYPES.MEDIUM
  return REVIEW_TYPES.BAD
}

// 获取评价等级文本
export function getRatingText(rating) {
  return REVIEW_RATING_TEXT[rating] || '未知'
}

// 获取评价等级颜色
export function getRatingColor(rating) {
  return REVIEW_RATING_COLOR[rating] || 'info'
}

// 获取标签类型
export function getTagType(tag) {
  if (REVIEW_TAGS.POSITIVE.includes(tag)) {
    return 'success'
  }
  if (REVIEW_TAGS.NEGATIVE.includes(tag)) {
    return 'danger'
  }
  return 'info'
}

// 计算好评率
export function calculateGoodReviewRate(stats) {
  const total = stats.good + stats.medium + stats.bad
  if (total === 0) return 0
  return ((stats.good / total) * 100).toFixed(1)
}

// 计算平均评分
export function calculateAverageRating(reviews) {
  if (!reviews || reviews.length === 0) return 0
  const total = reviews.reduce((sum, review) => sum + review.rating, 0)
  return (total / reviews.length).toFixed(1)
}

// 分析评价趋势
export function analyzeReviewTrend(reviews) {
  const last30Days = reviews.filter(review => {
    const reviewDate = new Date(review.createTime)
    const thirtyDaysAgo = new Date()
    thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30)
    return reviewDate >= thirtyDaysAgo
  })

  const previous30Days = reviews.filter(review => {
    const reviewDate = new Date(review.createTime)
    const sixtyDaysAgo = new Date()
    const thirtyDaysAgo = new Date()
    sixtyDaysAgo.setDate(sixtyDaysAgo.getDate() - 60)
    thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30)
    return reviewDate >= sixtyDaysAgo && reviewDate < thirtyDaysAgo
  })

  const currentAvg = calculateAverageRating(last30Days)
  const previousAvg = calculateAverageRating(previous30Days)

  return {
    current: currentAvg,
    previous: previousAvg,
    trend: currentAvg > previousAvg ? 'up' : currentAvg < previousAvg ? 'down' : 'stable',
    change: (currentAvg - previousAvg).toFixed(1)
  }
>>>>>>> c61637f (所有前后端正常登录)
}